
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <fstream>
#include <nlohmann/json.hpp>

#include "./CanvasWidget.h"
#include "qbe/src/layer/layer.hpp"
#include "qbe/src/layout/layout.hpp"
#include "qbe/src/message/message.hpp"

#include "qbe/src/canvas/ui_example/createLabel/ui.h"
#include "qbe/src/canvas/ui_example/state/ui.h"

#include "./Run.h"
#include "./transferStation.h"

#include "../../src/ql/views/drawing/line/createflexpathset.h"

#include "../editing/editing.hpp"
#include "../layout/settings.hpp"
#include "../state/state.hpp"
#include "../undoRedo/undoRedo.hpp"
#include "qbe/src/canvas/events/all.h"

#include "qbe/src/draw/draw.hpp"

#include "qbe/src/ui/ui.hpp"

#include "../select/select_info_display.hpp"
#include "../tools/tools_interface.h"

#include "../axis/render_grid.hpp"
#include "../image2d/image2d.hpp"
#include "../utils/kutils.h"

#include "../observe/observe.h"

#include "../operationLayer/operationLayer.h"

namespace qbe::canvas {
using json = nlohmann::json;

VsgWindow::VsgWindow(vsg::ref_ptr<vsgQt::Viewer> in_viewer, vsg::ref_ptr<vsg::WindowTraits> in_traits, QWindow* parent)
    : vsgQt::Window(in_viewer, in_traits, parent) {}

void VsgWindow::resizeEvent(QResizeEvent* e) {
  if (!windowAdapter)
    return;

  auto tx = convert_coord(x());
  auto ty = convert_coord(x());
  auto tw = convert_coord(width());
  auto th = convert_coord(height());

  if (title() == "map_window") {
    auto& app_axis = app->resource<axis::Axis>();
    app_axis.grid_scale = 10;
    tw = tw + 16;
    th = th + 39;
    traits->x = tx;
    traits->y = ty;
    traits->width = tw;
    traits->height = th;
    // map_widget->setGeometry(20, 20, tw + 20, th + 20);
    // this->resize(map_widget->size());
    // traits->width = map_widget->size().width();
    // traits->height = map_widget->size().height();

    // std::ifstream f("config/ecs/map_window.json");
    // json data = json::parse(f);

    // auto& app_traits = app->resource<render::Model>().windowTraits;
    // auto& app_axis = app->resource<axis::Axis>();
    // auto s = double(data["s"]);
    // tw = static_cast<double>(traits->width);
    // th = static_cast<double>(traits->height);
    // // auto tw_half = tw / 2.0f;
    // // auto th_half = th / 2.0f;
    // // tw = 200;
    // // th = 200;
    // // // th = tw;
    // // 更新相机
    // auto left = s * (-tw / 2.0f);
    // auto right = s * (tw / 2.0f);
    // auto top = s * (-th / 2.0f);
    // auto bottom = s * (th / 2.0f);

    // auto tdx = data["dx"];
    // auto tdy = data["dy"];

    // // auto dx = (s - 1) * app_axis.gl_dx + tdx;
    // // auto dy = (s - 1) * app_axis.gl_dy + tdy;
    // auto dx = 0;
    // auto dy = 0;

    // // auto left = data["left"];
    // // auto right = data["right"];
    // // auto top = data["top"];
    // // auto bottom = data["bottom"];

    // auto viewport = vsg::ViewportState::create(0, 0, tw, th);
    // auto ortho = vsg::Orthographic::create(left - dx, right - dx, top - dy, bottom - dy, 0.0f, 10.0f);
    // auto lookAt = vsg::LookAt::create(vsg::dvec3(0.0, 0.0, 5.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 1.0, 0.0));
    // auto new_camera = vsg::Camera::create(ortho, lookAt, viewport);
    // (*camera) = (*new_camera);
  } else {
    tw = tw + 16;
    th = th + 39;
    traits->x = tx;
    traits->y = ty;
    traits->width = tw;
    traits->height = th;
    // // 更新相机
    // auto viewport = vsg::ViewportState::create(0, 0, tw, th);
    // auto ortho = vsg::Orthographic::create(double(-tw / 2.0f), double(tw / 2.0f), double(-th / 2.0f), double(th / 2.0f), 0.0f, 10.0f);
    // auto lookAt = vsg::LookAt::create(vsg::dvec3(0.0, 0.0, 5.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 1.0, 0.0));
    // auto new_camera = vsg::Camera::create(ortho, lookAt, viewport);
    // (*camera) = (*new_camera);

    vsg::clock::time_point event_time = vsg::clock::now();
    windowAdapter->bufferedEvents.push_back(vsg::ConfigureWindowEvent::create(windowAdapter, event_time, convert_coord(x()), convert_coord(y()),
                                                                              convert_coord(width()), convert_coord(height())));
  }

  windowAdapter->resize();

  if (viewer)
    viewer->request();
}

void VsgWindow::keyPressEvent(QKeyEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::KeySymbol keySymbol, modifiedKeySymbol;
  vsg::KeyModifier keyModifier;

  if (keyboardMap->getKeySymbol(e, keySymbol, modifiedKeySymbol, keyModifier)) {
    vsg::clock::time_point event_time = vsg::clock::now();
    windowAdapter->bufferedEvents.push_back(vsg::KeyPressEvent::create(windowAdapter, event_time, keySymbol, modifiedKeySymbol, keyModifier));
  }

  if (viewer)
    viewer->request();

  // emit keyPressEventSig(e);
}

void VsgWindow::keyReleaseEvent(QKeyEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::KeySymbol keySymbol, modifiedKeySymbol;
  vsg::KeyModifier keyModifier;

  if (keyboardMap->getKeySymbol(e, keySymbol, modifiedKeySymbol, keyModifier)) {
    vsg::clock::time_point event_time = vsg::clock::now();
    windowAdapter->bufferedEvents.push_back(vsg::KeyReleaseEvent::create(windowAdapter, event_time, keySymbol, modifiedKeySymbol, keyModifier));
  }

  if (viewer)
    viewer->request();

  // emit keyReleaseEventSig(e);
}

void VsgWindow::mouseMoveEvent(QMouseEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::clock::time_point event_time = vsg::clock::now();

  auto [mask, button] = convertMouseButtons(e);
  auto [x, y] = convertMousePosition(e);

  if (x < traits->width && y < traits->height) {
    windowAdapter->bufferedEvents.push_back(vsg::MoveEvent::create(windowAdapter, event_time, x, y, mask));
  }

  if (viewer)
    viewer->request();
}

void VsgWindow::mousePressEvent(QMouseEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::clock::time_point event_time = vsg::clock::now();

  auto [mask, button] = convertMouseButtons(e);
  auto [x, y] = convertMousePosition(e);

  windowAdapter->bufferedEvents.push_back(vsg::ButtonPressEvent::create(windowAdapter, event_time, x, y, mask, button));

  if (viewer)
    viewer->request();

  // emit mousePressEventSig(e);
}

void VsgWindow::mouseReleaseEvent(QMouseEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::clock::time_point event_time = vsg::clock::now();

  auto [mask, button] = convertMouseButtons(e);
  auto [x, y] = convertMousePosition(e);

  windowAdapter->bufferedEvents.push_back(vsg::ButtonReleaseEvent::create(windowAdapter, event_time, x, y, mask, button));

  if (viewer)
    viewer->request();

  // emit mouseReleaseEventSig(e);
}

void VsgWindow::wheelEvent(QWheelEvent* e) {
  if (isMinimap()) {
    return;
  }

  if (!windowAdapter)
    return;

  vsg::clock::time_point event_time = vsg::clock::now();
  windowAdapter->bufferedEvents.push_back(
      vsg::ScrollWheelEvent::create(windowAdapter, event_time, e->angleDelta().y() < 0 ? vsg::vec3(0.0f, -1.0f, 0.0f) : vsg::vec3(0.0f, 1.0f, 0.0f)));

  if (viewer)
    viewer->request();

  // emit wheelEventSig(e);
}

bool VsgWindow::isMinimap() const {
  return title() == "map_window";
}

VsgWindow* createWindow(vsg::ref_ptr<vsgQt::Viewer> viewer, vsg::ref_ptr<vsg::WindowTraits> traits, vsg::ref_ptr<vsg::Group> vsg_scene,
                        vsg::ref_ptr<vsg::Camera>& camera, QWindow* parent, const QString& title = {}) {
  auto window = new VsgWindow(viewer, traits, parent);
  window->setTitle(title);
  window->initializeWindow();

  // if this is the first window to be created, use its device for future window creation.
  if (!traits->device)
    traits->device = window->windowAdapter->getOrCreateDevice();

  auto width_half = static_cast<double>(traits->width / 2);
  auto height_half = static_cast<double>(traits->height / 2);
  auto ortho = vsg::Orthographic::create(-width_half, width_half, -height_half, height_half, 0.0f, 10.0f);
  auto lookAt = vsg::LookAt::create(vsg::dvec3(0.0, 0.0, 5.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 1.0, 0.0));
  auto viewport = vsg::ViewportState::create(0, 0, traits->width, traits->height);
  camera = vsg::Camera::create(ortho, lookAt, viewport);
  auto commandGraph = vsg::createCommandGraphForView(*window, camera, vsg_scene);
  viewer->addRecordAndSubmitTaskAndPresentation({commandGraph});
  return window;
}

CanvasWidget::CanvasWidget(std::shared_ptr<qlib::Cell> cell, std::shared_ptr<qlib::Library> cell_lib, vsg::ref_ptr<vsgQt::Viewer> t_viewer,
                           vsg::ref_ptr<vsg::WindowTraits> t_windowTraits, vsg::ref_ptr<vsg::Options> t_options, QWidget* _map_widget,
                           QWidget* parent) {

  init_app();
  viewer = t_viewer;
  windowTraits = t_windowTraits;
  options = t_options;
  library = cell_lib;
  name = cell->name;
  map_widget = _map_widget;
  // map_widget->setMinimumSize({200, 200});
  // map_widget->setMaximumSize({500, 500});

  loadCell(cell->name);

  // widget->setGeometry(windowTraits->x, windowTraits->y, windowTraits->width, windowTraits->height);

  gridLayout = new QGridLayout();
  gridLayout->setSpacing(0);
  gridLayout->setContentsMargins(0, 0, 0, 0);

  ruler_x_widget = new RulerWidget("x", 300, 20);
  ruler_y_widget = new RulerWidget("y", 20, 300);

  vsg_widget = new QWidget();
  vsg_layout = new QVBoxLayout(vsg_widget);
  vsg_layout->setSpacing(0);
  vsg_layout->setContentsMargins(8, 31, 9, 9);
  vsg_layout->addWidget(widget);

  gridLayout->addWidget(ruler_x_widget, 0, 1, 1, 1);
  gridLayout->addWidget(ruler_y_widget, 1, 0, 1, 1);
  gridLayout->addWidget(vsg_widget, 1, 1, 1, 1);

  QHBoxLayout* horizontalLayout = new QHBoxLayout();
  horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
  m_ele_info = new QLineEdit();
  m_ele_info->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  m_ele_info->setAlignment(Qt::AlignLeft | Qt::AlignTrailing | Qt::AlignVCenter);
  m_ele_info->setObjectName(QString::fromUtf8("lineEdit"));
  m_ele_info->setFrame(false);
  m_ele_info->setReadOnly(true);
  m_ele_info->setText("element info");

  horizontalLayout->addWidget(m_ele_info);

  m_progress_bar = new ProgressBarDisplay();
  m_progress_bar->setFixedHeight(20);
  m_progress_bar->setDisplay(false);
  horizontalLayout->addWidget(m_progress_bar);

  m_operator_type = new QLineEdit();
  // 设置大小策略为Expanding，使QLineEdit可以根据内容自动调整大小
  m_operator_type->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  m_operator_type->setObjectName(QString::fromUtf8("lineEdit_2"));
  m_operator_type->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
  m_operator_type->setFrame(false);
  m_operator_type->setReadOnly(true);
  m_operator_type->setText("operator_type");

  horizontalLayout->addWidget(m_operator_type);

  QVBoxLayout* verticalLayout = new QVBoxLayout(this);
  verticalLayout->setContentsMargins(0, 0, 0, 0);
  verticalLayout->addLayout(gridLayout);
  verticalLayout->addLayout(horizontalLayout);

  qApp->installEventFilter(this);  // 安装事件过滤器到QApplication

  qbe::UiMessage::LayoutAdaptMessage mes;
  this->uiSendMessage(mes);
}
CanvasWidget::~CanvasWidget() {
  qApp->removeEventFilter(this);  // 在对象销毁时移除事件过滤器
  delete t_map_widget;
}

// void CanvasWidget::setMinimapWidget(QWidget* widget) {
//   // map_widget = widget;
//   // resetMinimapWidget();
// }
// void CanvasWidget::resetMinimapWidget() {
//   if (!map_widget) {
//     return;
//   }

//   if (!map_widget->layout()) {
//     map_widget->setLayout(new QVBoxLayout);
//   }

//   // QWidget* window_widget = QWidget::createWindowContainer(map_window, nullptr);
//   // window_widget->setGeometry(0, 0, 200, 200);
//   // map_window->initializeWindow();

//   auto* item = map_widget->layout()->takeAt(0);
//   if (item) {
//     if (item->widget()) {
//       item->widget()->setParent(nullptr);
//       item->widget()->hide();
//     }
//     delete item;
//   }
//   map_widget->layout()->addWidget(t_map_widget);
//   t_map_widget->show();
//   map_widget->layout()->update();

//   // t_map_widget->setMinimumSize({200, 200});
//   // t_map_widget->setFixedSize(map_widget->size());
//   // t_map_widget->setMinimumSize(map_widget->size());
//   // map_widget->setMaximumSize({201, 201});
//   auto width = map_widget->size().width();
//   auto height = map_widget->size().height();
//   t_map_widget->setGeometry(20, 20, width + 20, height + 20);
//   t_map_widget->resize(map_widget->size());

//   map_window->traits->width = width;
//   map_window->traits->height = height;
// }

void CanvasWidget::setReceiveGlobalKeyEVent(bool receive) {
  receiveGlobalKeyEvent = receive;
}
void CanvasWidget::setEleInfo(const QString& msg) {
  QFontMetrics elidfont(m_ele_info->font());
  m_ele_info->setText(elidfont.elidedText(msg, Qt::ElideRight, m_ele_info->width()));
  m_ele_info->setToolTip(msg);
}
void CanvasWidget::setOperatorInfo(const QString& msg) {
  if (m_operator_type) {
    QFontMetrics elidfont(m_operator_type->font());
    m_operator_type->setText(elidfont.elidedText(msg, Qt::ElideRight, m_operator_type->width()));
    m_operator_type->setToolTip(msg);
  }
}

void CanvasWidget::addCellState(std::shared_ptr<qlib::Cell> cell, CellState state) {
  m_cell_states[cell] = state;
}

void CanvasWidget::regenerationReference() {
  auto query = app.get_super<qbe::ecs::Query>(0);
  auto& cmd = query.get_resource<qbe::layout::LayoutCmd>();

  for (auto cell_state : m_cell_states) {
    if (cell_state.second == CellState::CHANGED) {
      // update_cell  第一层就是有变动的单元
      auto refs = cell->reg.view<qlib::Reference::s_ptr>();
      for (auto [e, i] : refs.each()) {
        if (i->cell == cell_state.first) {
          cmd.update_cell(i->cell, true);
        } else {
          // update_cell 查看第一层依赖的单元是否有变动
          std::unordered_map<std::string, std::shared_ptr<qlib::Cell>> depend_cells;
          i->cell->dependencies(true, depend_cells);
          auto itr = depend_cells.find(cell_state.first->name);
          if (itr != depend_cells.end()) {
            if (itr->second == cell_state.first)  // 排除不同文件单元重名的情况
            {
              cmd.update_cell(i->cell, true);
            }
          }
        }
      }
    }
  }
  m_cell_states.clear();
}

bool CanvasWidget::eventFilter(QObject* obj, QEvent* event) {
  if (receiveGlobalKeyEvent && enable && app.contains_resource<vsg::ref_ptr<qbe::input::HandleBundle>>()) {
    bool is_press = event->type() == QEvent::KeyPress;
    bool is_release = event->type() == QEvent::KeyRelease;

    if (is_press || is_release) {
      static vsgQt::KeyboardMap keyboardMap;

      QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);

      vsg::KeySymbol keySymbol, modifiedKeySymbol;
      vsg::KeyModifier keyModifier;

      if (keyboardMap.getKeySymbol(keyEvent, keySymbol, modifiedKeySymbol, keyModifier)) {
        auto& handle = app.resource<vsg::ref_ptr<qbe::input::HandleBundle>>();

        if (is_press) {
          vsg::KeyPressEvent* e = new vsg::KeyPressEvent;
          e->keyBase = keySymbol;
          e->keyModified = modifiedKeySymbol;
          e->keyModifier = keyModifier;

          // handle->apply(*e);
        } else if (is_release) {

          vsg::KeyReleaseEvent* e = new vsg::KeyReleaseEvent;
          e->keyBase = keySymbol;
          e->keyModified = modifiedKeySymbol;
          e->keyModifier = keyModifier;

          if (keyEvent->text().toStdString() == "\r") {
            e->keyBase = vsg::KEY_Return;
            handle->getGlobalKeyEvent(*e);
          } else {
            handle->getGlobalKeyEvent(*e);
          }

          // if (keyModifier != vsg::KeyModifier::MODKEY_OFF) {
          //   handle->apply(*e);
          // } else if (keyEvent->text().toStdString() == "\r") {
          //   e->keyBase = vsg::KEY_Return;
          //   handle->apply(*e);
          // }
        }
      }
    }
  }

  if (obj == window) {
    if (event->type() == QEvent::MouseMove) {
      if (this->window->isActive()) {
        this->window->requestActivate();
      }
    }
  }

  // 继续传递事件到默认的事件处理
  return QWidget::eventFilter(obj, event);
}

void CanvasWidget::init_app() {
  // ecs::App app;

  app.insert_resource(vsg_layout);
  app.insert_resource(this);

  ecs::Query* query = new ecs::Query(app);
  app.insert_resource(query);

  app.add_plugins(ecs::DefaultPlugin());
  app.add_plugins(msg::MessagePlugin());
  app.add_plugins(input::Input());
  app.add_plugins(render::Render());
  app.add_plugins(axis::AxisPlugin());
  app.add_plugins(adsorb::AdsorbPlugin());
  app.add_plugins(axis::RenderGridPlugin());
  app.add_plugins(select::SelectPlugin());
  app.add_plugins(layer::LayerPlugin());
  app.add_plugins(layout::LayoutPlugin());
  app.add_plugins(select::SelectInfoDisplayPlugin());
  app.add_plugins(tools::ToolsInterfacePlugin());
  app.add_plugins(image2d::Plugin());

  app.add_plugins(state::StateManager());
  app.add_plugins(undoRedoT::UndoRedoPlugin());
  app.add_plugins(editing::EditingPlugin());
  app.add_plugins(draw::DrawPlugin());
  app.add_plugins(propertyUi::Plugin());
  app.add_plugins(qbe::ol::Plugin());

#ifdef _DEBUG
  app.add_plugins(observe::Plugin());
#endif

  // 渲染顺序
}

void CanvasWidget::test() {}

void CanvasWidget::setEnable(bool e) {
  enable = e;
  app.resource<bool>() = e;

  if (!e) {
    this->uiSendMessage(qbe::UiMessage::DRCCancelHighlight());
  }
}

void CanvasWidget::loadCell(std::string name) {
  QWindow* parent = nullptr;

  // json
  std::ifstream f("config/settings.json");
  json data = json::parse(f);

  app.init_resource<layout::Settings>();
  app.resource<layout::Settings>().fill = bool(data["display.fill"]);
  app.resource<layout::Settings>().pin_show_scale = double(data["display.pin_show_scale"]);

  cell = library->cell_map[name];
  app.init_resource<qlib::Library::s_ptr>(library);
  app.init_resource<qlib::Cell::s_ptr>(cell);
  app.init_resource<bool>(false);
  app.init_resource<std::string>(name);
  app.resource<layout::CellCmd>().cell = cell;

  auto& render_model = app.resource<render::Model>();

  render_model.scene = vsg::Group::create();

  map_window = createWindow(viewer, windowTraits, render_model.scene, render_model.map_camera, nullptr, "map_window");
  map_window->camera = render_model.map_camera;
  map_window->app = &app;
  t_map_widget = QWidget::createWindowContainer(map_window, map_widget);
  // widget->setGeometry(windowTraits->x, windowTraits->y, windowTraits->width, windowTraits->height);
  map_window->map_widget = t_map_widget;

  window = createWindow(viewer, windowTraits, render_model.scene, render_model.camera, nullptr, "window");
  window->camera = render_model.camera;
  window->app = &app;
  // window->installEventFilter(this);
  widget = QWidget::createWindowContainer(window, nullptr);

  render_model.viewer = viewer;
  render_model.windowTraits = window->traits;
  render_model.options = options;
  render_model.window = window;
  render_model.map_window = map_window;

  app.init_resource<vsg::ref_ptr<vsg::WindowTraits>>(window->traits);
  app.init_resource<vsgQt::Window*>(window);
  app.init_resource<vsg::ref_ptr<vsgQt::Viewer>>(viewer);
  app.init_resource<vsg::ref_ptr<vsg::Options>>(options);

  // 初始化
  app.run_setup();

  // 定时运行
  timer_run = new QTimer(this);
  connect(timer_run, &QTimer::timeout, [&]() {
    if (app.resource<bool>()) {
      auto& bus = this->app.get_bus();

      // 先识别鼠标事件

      // this->viewer->render();

      // app 运行

      // // // 编译
      // if (app.resource<render::Model>().is_compile) {
      //   SPDLOG_INFO("render compile");
      //   this->viewer->compile();
      //   app.resource<render::Model>().is_compile = false;
      // }
      // // this->viewer->compile();
      // if (this->fps % 10) {
      //   SPDLOG_INFO("fps render compile");
      //   this->viewer->compile();
      // }
      // this->fps++;

      this->viewer->pollEvents(false);
      this->viewer->handleEvents();
      this->app.run();

      if (this->viewer->advanceToNextFrame()) {
        this->viewer->update();
        this->viewer->recordAndSubmit();
        this->viewer->present();
      }
      this->viewer->requests = 0;

      bus.clearAllReceive();

      ui_run();
    }
  });
  timer_run->start(15);
}

void CanvasWidget::ui_run() {
  std::vector<std::any>& messages = app.get_bus().getSendQue();

  if (!messages.empty()) {
    for (auto& m : messages) {
      const std::type_info& t = m.type();
      if (t == typeid(layout::Event)) {
        auto e = std::any_cast<layout::Event>(m);
        SPDLOG_INFO("layout event");
        // this->viewer->compile();
      }
    }
    /*InputDialog* dialog = new InputDialog;
    dialog->show();*/
    emit sig_run_ui(messages);
  };

  /*StateDialog* stateDia = StateDialog::Instane();
  stateDia->updateButtonStates();*/

  messages.clear();
}

void CanvasWidget::arrayOkMessage(UiMessage::ArrayUi_Ok mes) {
  auto& bus = app.get_bus();
  auto& receive_que = bus.getReceiveQue();

  auto& event = receive_que.emplace_back();
  event = std::make_any<UiMessage::ArrayUi_Ok>(mes);
}

void CanvasWidget::rulerDraw(const QList<QVector<double>>& lines_x, const QList<QVector<double>>& lines_y, const QVector2D& pos) {
  ruler_x_widget->onDraw(lines_x, lines_y, pos);
  ruler_y_widget->onDraw(lines_x, lines_y, pos);
}

void CanvasWidget::wheelEventSlot(QWheelEvent* e) {
  SPDLOG_INFO("name: {}", name);
}

void CanvasWidget::setProgressBarDisplay(bool display) {
  m_ele_info->setVisible(!display);
  m_operator_type->setVisible(!display);
  m_progress_bar->setDisplay(display);
  m_progress_bar->setProgressValue(0);
}

void CanvasWidget::setValueRange(int maximum, int minimum) {
  m_progress_bar->setMaximumValue(maximum);
  m_progress_bar->setMinimumValue(minimum);
}

void CanvasWidget::setProgressValue(int value) {
  m_progress_bar->setProgressValue(value);
}

void CanvasWidget::setProgressText(QString text) {
  m_progress_bar->setDisplayContent(text);
}

}  // namespace qbe::canvas
//
